package com.icid.store.command
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.icid.store.business.delegate.CartDelegate;
	import com.icid.store.event.GetCartListEvent;
	import com.icid.store.model.CartModelLocator;
	import com.icid.store.vo.CartVO;
	
	import mx.rpc.IResponder;

	public class GetCartListCommand extends CommandBase implements ICommand, IResponder
	{
		private var delegate:CartDelegate;
		private var cartModel:CartModelLocator = CartModelLocator.getInstance();
		private var getCartListEvent:GetCartListEvent;
		public function GetCartListCommand()
		{
			super();
			delegate = new CartDelegate(this);
		}
		
		override public function execute(event:CairngormEvent):void
		{
			getCartListEvent = GetCartListEvent(event);
			delegate.read(getCartListEvent.cid);
		}
		
		override public function result(data:Object):void
		{
//			trace(data.result);
			cartModel.cartList.removeAll();
			for(var i:int=0;i<data.result.length;i++)
			{
				var cartVO:CartVO = new CartVO();
				cartVO.id = data.result[0].id;
				cartVO.pid = data.result[0].pid;
				cartVO.quantity = data.result[0].quantity;
				cartVO.time = data.result[0].time;
				cartModel.cartList.addItem(cartVO);
			}
		}
		
	}
}